import {defineStore} from "pinia";
import {ref} from "vue";
import {getLocalSessionItem, setLocalSessionItem} from "@/utils/localSession";

const memberKey = "MEMBER";

const useMemberStore = defineStore("userStore", () => {
    const member = ref<any>(getLocalSessionItem(memberKey))

    function setMember(value: any) {
        member.value = value;
        setLocalSessionItem(memberKey, value);
    }

    function getMember() {
        return member.value;
    }

    function clearMember() {
        member.value = null;
        setLocalSessionItem(memberKey, {});
    }

    function isLogin() {
        return !(member.value.token === undefined || member.value.token === "");
    }

    return {
        member,
        setMember,
        getMember,
        clearMember,
        isLogin
    }
})

export default useMemberStore